import router from "./router";
import store from './store'
import { getToken } from "./utils/auth";
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style


NProgress.configure({ showSpinner: false }) // NProgress Configuration
    //白名单地址
const whiteList = ['/login', '/404', '/500']

//路由守卫
router.beforeEach((to, from, next) => {
    NProgress.start(); //显示进度条
    //获取token
    const hasToken = getToken()
        //是否在白名单
    if (whiteList.indexOf(to.path) !== -1) {
        next()
        NProgress.done(); //完成进度条
    } else {
        console.log(hasToken)
        if (hasToken) {
            next()
            NProgress.done(); //完成进度条
        } else {
            next('/login')
            NProgress.done(); //完成进度条
        }

    }
})

router.afterEach((to, from) => {
    NProgress.done(); //完成进度条
})